<template>
  <div>
    <!-- 右边基本表格 -->
    <BasicTable @register="registerTable">
      <!-- 表格标题 -->
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ title }} </span>
      </template>
      <!-- 表格右上角自定义按钮（新增...） -->
      <template #toolbar>
        <a-button @click="handleRefresh({})">
          <Icon icon="fa fa-refresh" /> {{ t('刷新机床时间') }}
        </a-button>
        <a-button @click="handleForm({})" v-auth="'m8:machine:edit'">
          <!-- v-if="hasPermission(['m8:machine:edit'])" -->
          <Icon icon="fluent:add-12-filled" /> {{ t('添加机床') }}
        </a-button>
        <a-button @click="handleSj({})" v-auth="'m8:machine:check:sj'">
          <Icon icon="simple-line-icons:check" /> {{ t('首检机床') }}
        </a-button>
        <a-button @click="handleGcj({})" v-auth="'m8:machine:check:gcj'">
          <Icon icon="simple-line-icons:check" /> {{ t('过程检机床') }}
        </a-button>
        <a-button
          v-for="(item, index) in butData"
          :key="index"
          :type="item.type"
          @click="item.do"
          v-auth="item.auth"
        >
          <Icon :icon="item.icon" /> {{ t(item.title) }}
        </a-button>
      </template>
      <!-- 表格插槽 -->
      <template #beginTime="{ record }">
        {{ record.beginTime }}
        <a-button
          v-if="record.beginTime"
          type="default"
          size="small"
          style="background: #3c8dbc; color: #fff; margin-right: 5px"
        >
          {{ getAgoAt(record.beginTime) }}
        </a-button>
      </template>
      <template #endTime="{ record }">
        {{ record.endTime }}
        <a-button
          v-if="record.endTime"
          type="default"
          size="small"
          style="background: #10c6f3; color: #fff; margin-right: 5px"
        >
          {{ getAgoAt(record.endTime) }}
        </a-button>
      </template>

      <template #taskid="{ record }">
        <!-- @click="handleForm({ })" -->
        <div v-if="record.task">
          <a @click="handleRouterList(record.task.orderPic.id)"> 数铣配置</a>
          <span v-if="record.task">
            <span v-if="record.task.orderPic">
              {{
                '【' +
                (record.task.orderPic.picno || '') +
                '】【' +
                (record.task.orderPic.picname || '') +
                '】'
              }}
            </span>
            <sapn v-if="record.task.oper">
              {{ '【' + (record.task.oper.operName || '') + '】' }}
            </sapn>
          </span>
          <div style="height: 10px"></div>
          <a @click="openTaskList(record.task.taskCode)"
            ><Icon icon="simple-line-icons:clock" />修改加工时长</a
          >
          <span v-if="record.task">
            {{
              '   加(' +
              (record.task.sjjgtime || '无') +
              ') 调(' +
              (record.task.sjtsTime || '无') +
              ') 完(' +
              (record.overQty || '无') +
              ')'
            }}
            <span v-if="record.task.orderPic">
              {{ '图(' + (record.task.orderPic.iqty || '无') + ')' }}
            </span>
          </span>
        </div>
      </template>
      <template #task_taskCode="{ record }">
        <a @click="orderCheckList(record.task.taskCode)"
          ><Icon
            icon="ant-design:fast-forward-filled"
            style="margin-right: 10px; font-size: 18px"
          />检验明细
        </a>
        <div style="margin: 10px 0 5px">下次检验时间：</div>
        <div v-if="record.task && record.task.nextCheckDate">
          <span style="padding: 2px 5px; background: #3c8dbc; border-radius: 5px; color: #fff">{{
            record.task.nextCheckDate || ''
          }}</span>
        </div>
      </template>

      <template #name="{ record }">
        <a @click="handleForm({ code: record.id })">
          <a style="color: red; font-size: large; font-weight: bold">
            {{ record.name }}
          </a>
        </a>
      </template>

      <template #tuzhi="{ record }">
        <BasicUpload
          v-model:value="record.dataMap"
          :bizKey="record.id"
          :bizType="'m8OperCheck_file'"
          :readonly="true"
        />
      </template>

      <!-- 操作列的下拉选择 -->

      <template #operate="{ record }">
        <div style="display: flex; justify-content: space-around">
          <a-dropdown :trigger="['click']">
            <a-button @click.prevent>
              <!-- <Icon icon="fluent:add-12-filled" /> {{ t('添加机床') }} -->
              机 床 <DownOutlined />
            </a-button>
            <!-- </div> -->
            <template #overlay>
              <a-menu @click="onClick">
                <a-popconfirm
                  title="是否确认开机？"
                  ok-text="是"
                  cancel-text="否"
                  @confirm="machineEnable(record.code, '0')"
                >
                  <a-menu-item
                    v-if="record.machineStatus == '2' && hasPermission(['m8:machine:open'])"
                    key="1"
                    ><Icon icon="simple-line-icons:control-play" />开机</a-menu-item
                  >
                </a-popconfirm>
                <a-popconfirm
                  title="是否确认停机？"
                  ok-text="是"
                  cancel-text="否"
                  @confirm="machineEnable(record.code, '1')"
                >
                  <a-menu-item
                    v-if="record.machineStatus != '2' && hasPermission(['m8:machine:stop'])"
                    key="2"
                    ><Icon icon="ant-design:poweroff-outlined" />停机</a-menu-item
                  >
                </a-popconfirm>
                <a-menu-item
                  v-if="record.machineStatus != '2' && hasPermission(['m8:order:flow:bcQus:edit'])"
                  @click="handleBC(record)"
                  key="4"
                  ><Icon icon="ant-design:warning-filled" />BC反馈</a-menu-item
                >
                <!-- v-if="record.canDebug" -->
                <a-menu-item
                  v-if="record.canDebug && hasPermission(['m8:machine:debug:edit'])"
                  @click="addDebugData(record)"
                  key="5"
                  ><Icon icon="ant-design:retweet-outlined" />调试</a-menu-item
                >
              </a-menu>
            </template>
          </a-dropdown>

          <a-dropdown
            :trigger="['click']"
            v-if="record.task && record.task.taskCode && record.task.oper && record.task.orderPic"
          >
            <a-button @click.prevent> 任 务 <DownOutlined /> </a-button>
            <template #overlay>
              <a-menu @click="onClick">
                <a-menu-item
                  v-if="
                    record.canOver &&
                    hasPermission(['m8:machine:over:edit', 'm8:machine:over:view'])
                  "
                  @click="addOverData(record, 0, '')"
                  key="1"
                  ><Icon icon="ant-design:check-square-filled" />完成</a-menu-item
                >
                <a-menu-item
                  v-if="record.canPush && hasPermission(['m8:machine:task:stop'])"
                  @click="addOverData(record, 1, '')"
                  key="2"
                  ><Icon icon="ant-design:pause-circle-filled" />暂停</a-menu-item
                >
                <a-menu-item
                  v-if="record.canPush && hasPermission(['m8:machine:task:delay'])"
                  @click="addOverData(record, 2, '')"
                  key="3"
                  ><Icon icon="simple-line-icons:shuffle" />延后</a-menu-item
                >
                <a-menu-item
                  v-if="record.canPush && hasPermission(['m8:machine:task:chage'])"
                  @click="addOverData(record, 3, '')"
                  key="4"
                  ><Icon icon="ant-design:retweet-outlined" />换机</a-menu-item
                >
                <a-menu-item
                  v-if="
                    record.canOver &&
                    record.machineStatus == '1' &&
                    hasPermission(['m8:machine:over:edit', 'm8:machine:over:view'])
                  "
                  @click="addOverData(record, 0, '99')"
                  key="1"
                  ><Icon icon="ant-design:check-square-filled" />过程完工</a-menu-item
                >
              </a-menu>
            </template>
          </a-dropdown>
          <!-- </div> -->

          <a-dropdown
            :trigger="['click']"
            v-if="record.task && record.task.taskCode && record.task.oper && record.task.orderPic"
          >
            <a-button @click.prevent> 检 验 <DownOutlined /> </a-button>
            <template #overlay>
              <a-menu @click="onClick">
                <a-menu-item
                  key="1"
                  v-if="record.task.bsj != '1' && hasPermission(['m8:machine:check:sjts'])"
                  @click="handleBsj(record)"
                  ><Icon
                    icon="simple-line-icons:check"
                    :style="{ color: 'green' }"
                  />首检提示</a-menu-item
                >
                <a-menu-item
                  v-if="record.canFcheck && hasPermission(['m8:machine:check:sj'])"
                  @click="addCheckData(record, 1)"
                  key="2"
                  ><Icon
                    :style="{ color: 'green' }"
                    icon="simple-line-icons:check"
                  />首检</a-menu-item
                >

                <a-menu-item
                  v-if="record.canPcheck && hasPermission(['m8:machine:check:gcj'])"
                  @click="addCheckData(record, 2)"
                  key="3"
                  ><Icon
                    :style="{ color: 'orange' }"
                    icon="simple-line-icons:check"
                  />巡检</a-menu-item
                >
              </a-menu>
            </template>
          </a-dropdown>
        </div>

        <div style="display: flex; justify-content: space-around; margin-top: 10px">
          <a-button
            type="default"
            size="small"
            style="background: #00c0ef; color: #fff"
            @click="addRemark(record)"
            v-auth="'m8:machine:remark:edit'"
          >
            <Icon icon="simple-line-icons:pencil" /> {{ t('加工备注') }}
          </a-button>

          <a-button
            type="default"
            @click="remarksPush(record)"
            size="small"
            style="background: #00c0ef; color: #fff"
            v-auth="'m8:order:pic:viewRemark'"
          >
            <Icon icon="ant-design:search-outlined" /> {{ t('备注') }}
          </a-button>

          <a-button
            type="default"
            @click="openPool(record)"
            size="small"
            style="background: #00c0ef; color: #fff"
            v-auth="'m8:machine:view'"
          >
            <!-- <Icon icon=" ant-design:search-outlined" /> {{ t('任务队列') }} -->
            <Icon icon="simple-line-icons:note" /> {{ t('任务队列') }}
          </a-button>
        </div>
      </template>
    </BasicTable>

    <!-- </PageWrapper> -->
    <!-- 基础编辑新增 -->
    <InputForm @register="registerDrawer" @success="handleSuccess" />
    <!-- 页签方式编辑 -->
    <InputFormTabs @register="registerDrawer2" @success="handleSuccess" />

    <Modal @register="registerModal" @success="handleSuccess" />
    <DebugModal @register="registerDebugModal" @success="handleSuccess" />
    <OperCheck @register="registerCheckForm" @success="handleSuccess" />
    <CheckTipModal @register="checkTipRegister" @success="handleSuccess" />

    <!-- 编程反馈 -->
    <BCDrawerForm @register="registerBCDrawer" @success="handleSuccess" />
    <TipList @register="registerTipDrawer" />
    <PoolList @register="registerPoolDrawer" />
    <RemarkFormTabs @register="registerRemarkDrawer" />
    <BasicDrawer
      v-bind="$attrs"
      @register="registerCheckDrawer"
      :showFooter="false"
      width="80%"
      title="检验明细"
    >
      <CheckList :taskCode="taskCode" />
    </BasicDrawer>
    <BasicDrawer
      v-bind="$attrs"
      @register="registerSxDrawer"
      :showFooter="false"
      width="80%"
      title="数铣明细"
    >
      <SxList :orderPic="orderPic" />
    </BasicDrawer>
    <BasicDrawer
      v-bind="$attrs"
      @register="registerTaskDrawer"
      :showFooter="false"
      width="80%"
      title="任务明细"
    >
      <TaskList :taskCode="taskCode" />
    </BasicDrawer>

    <!-- 图纸备注 -->
    <BasicDrawer
      v-bind="$attrs"
      @register="registerRemarksDrawer"
      :showFooter="false"
      width="80%"
      :maskClosable="true"
      title="图纸备注"
    >
      <Remarks :picId="picId" />
    </BasicDrawer>
  </div>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsM8MachineMachineList',
  });
</script>
<script lang="ts" setup>
  import { defineComponent, onMounted, ref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { customListData } from '/@/api/test/testData';
  import { enable, disable, refresh } from '/@/api/m8/machine/machine';
  import { BasicUpload } from '/@/components/Upload';
  import { listSet, adminPath } from '/@/api/machine/machine';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';
  import InputFormTabs from './formTabs.vue';
  import { schemasData, tabConfigData } from '/@/utils/custom';
  import { DownOutlined } from '@ant-design/icons-vue';
  import type { MenuProps } from 'ant-design-vue';
  import BCDrawerForm from '/@/views/m8/order/flow/bc/BCDrawerForm.vue';
  import { BasicDrawer } from '/@/components/Drawer';
  import Modal from './Modal.vue';
  import DebugModal from './debugModal.vue';
  import OperCheck from '/@/views/m8/machine/check/form.vue';
  import TipList from '../tips/list.vue';
  import PoolList from '../task/poolList.vue';
  import RemarkFormTabs from '../task/remark/formTabs.vue';
  import CheckList from '../../order/flow/check/list.vue';
  import SxList from '../../order/sx/list.vue';
  import TaskList from '../task/list.vue';
  import Remarks from '/@/views/m8/order/remarks.vue';
  import { usePermission } from '/@/hooks/web/usePermission';
  import CheckTipModal from './checkTipModal.vue';
  import { useModal } from '/@/components/Modal';
  import { handleExport } from '/@/utils/export';

  const [registerModal, { openDrawer: openModal }] = useDrawer();
  const [registerDebugModal, { openDrawer: openDebugModal }] = useDrawer();
  const [checkTipRegister, { openModal: openCheckTipModal }] = useModal();
  const [registerCheckForm, { openDrawer: openCheckForm }] = useDrawer();
  const [registerCheckDrawer, { openDrawer: openCheckDrawer }] = useDrawer();
  const [registerTaskDrawer, { openDrawer: openTaskDrawer }] = useDrawer();
  const [registerRemarksDrawer, { openDrawer: openRemarkskDrawer }] = useDrawer();
  const { t } = useI18n('test.testData');
  const { showMessage } = useMessage();
  const { hasPermission } = usePermission();
  const props = defineProps({
    idIn: String,
  });

  let taskCode = ref('');
  let picId = ref('');
  //配置表单内容
  // const searchForm: FormProps = {
  //   baseColProps: { lg: 6, md: 8 }, // 表单栅格布局
  //   labelWidth: 100, // 表单标签宽度
  //   schemas: [
  //     {
  //       label: t('机床号'),
  //       field: 'selIds',
  //       component: 'InputTextArea',
  //       componentProps: {
  //         maxlength: 2000,
  //         rows: 1,
  //       },
  //     },
  //     {
  //       label: t('订单号'),
  //       field: 'order.ccode',
  //       component: 'Input',
  //     },
  //     {
  //       label: t('加工名称'),
  //       field: 'order.jgname',
  //       component: 'Input',
  //     },
  //     {
  //       label: t('图纸'),
  //       field: 'task.orderPic.picno',
  //       component: 'Input',
  //     },
  //     {
  //       label: t('机床名称'),
  //       field: 'name',
  //       component: 'Input',
  //     },
  //     {
  //       label: t('机床状态'),
  //       field: 'machineStatus',
  //       component: 'Select',
  //       componentProps: {
  //         dictType: 'm8_machine_status', //参数字典配置
  //       },
  //     },
  //     {
  //       label: t('负责工序名称'),
  //       field: 'operNames',
  //       component: 'Input',
  //     },
  //     {
  //       label: t('机床限定'),
  //       field: 'id_in',
  //       component: 'Input',
  //       show: false,
  //     },
  //   ],
  // };
  //配置表单内容
  const searchForm = ref<FormProps>({
    baseColProps: { lg: 6, md: 8 }, // 表单栅格布局
    labelWidth: 100, // 表单标签宽度
    schemas: [],
  });

  let layVoucherView = ref<any>({});
  let listTabConfig = ref<any>({});
  let butData = ref<any>([]);
  const getTitle = ref({
    // 表格标题图标
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: listTabConfig.value.title,
  });

  let title = ref('');
  let orderPic = ref('');

  const tableColumns: BasicColumn[] = [
    {
      title: t('开始时间'),
      dataIndex: 'beginTime',
      key: 'a.begin_time',
      sorter: true,
      width: 230,
      align: 'left',
      // ifShow: false,
      slot: 'beginTime',
    },
    {
      title: t('结束时间'),
      dataIndex: 'endTime',
      key: 'a.end_time',
      sorter: true,
      width: 230,
      align: 'left',
      // ifShow: false,
      slot: 'endTime',
    },
    {
      title: t('状态'),
      dataIndex: 'machineStatus',
      key: 'a.machine_status',
      sorter: true,
      width: 80,
      align: 'center',
      dictType: 'm8_machine_status',
    },
    {
      title: t('负责工序'),
      dataIndex: 'operNames',
      key: 'a.oper_names',
      sorter: true,
      width: 100,
      align: 'left',
    },
    {
      title: t('图号-名称-工序'),
      dataIndex: 'task.id',
      key: 'a.taskid',
      sorter: true,
      width: 400,
      align: 'left',
      slot: 'taskid',
    },
    {
      title: t('工价'),
      dataIndex: 'task.orderSx.fprice',
      key: 'sx.fprice',
      sorter: true,
      width: 80,
      align: 'center',
    },
    {
      title: t('检验记录'),
      dataIndex: 'task.taskCode',
      key: 'a.task',
      sorter: true,
      width: 200,
      align: 'left',
      slot: 'task_taskCode',
    },
    {
      title: t('机床'),
      dataIndex: 'name',
      key: 'a.name',
      sorter: true,
      width: 80,
      align: 'center',
      fixed: 'right',
      // dictType: 'sys_status',
      slot: 'name',
    },
    {
      title: t('图纸'),
      sorter: false,
      width: 80,
      align: 'center',
      fixed: 'right',
      slot: 'tuzhi',
    },
    {
      title: t('操作'),
      width: 260,
      align: 'center',
      fixed: 'right',
      slot: 'operate',
    },
  ];

  /*
   * 将时间戳转化为 “几周前” 的形式
   */
  function getAgoAt(date) {
    if (!date) {
      return '';
    }
    var current_time = new Date().getTime() / 1000;
    var paramDate = Date.parse(date) / 1000;
    var diff = current_time - paramDate;
    var sign = '前';
    if (diff < 0) {
      diff = -1 * diff;
      sign = '后';
    }
    var agoAt = '刚刚';
    var timePoints = [
      { value: 60 * 60 * 24 * 365, suffix: '年' + sign, max: 2 },
      { value: 60 * 60 * 24 * 30, suffix: '月' + sign, max: 12 },
      { value: 60 * 60 * 24 * 7, suffix: '周' + sign, max: 4 },
      { value: 60 * 60 * 24, suffix: '天' + sign, max: 7 },
      { value: 60 * 60, suffix: '小时' + sign, max: 23 },
      { value: 60 * 10, suffix: '0分钟' + sign, max: 5 },
    ];
    for (var i = 0; i < timePoints.length; i++) {
      var point = timePoints[i];
      var mode = Math.floor(diff / point.value);
      if (mode >= 1) {
        agoAt = Math.min(mode, point.max) + point.suffix;
        break;
      }
    }
    return agoAt;
  }

  onMounted(async () => {
    const res = await listSet({ viewCode: 'machine_list' });
    title.value = res.layVoucherView.name;
    layVoucherView.value = res.layVoucherView;

    searchForm.value.schemas = schemasData(layVoucherView.value.listQuery.queryCols);
    searchForm.value.schemas?.forEach((item) => {
      if (item.component == 'InputTextArea') {
        item.componentProps = {
          maxlength: 2000,
          rows: 1,
        };
      }
    });
    butData.value = layVoucherView.value.headBtns; //表格右上角按钮
    butData.value.forEach((item) => {
      if (item.btnKey == 'btnExport') {
        item.do = () => btnExport();
      }
    });

    listTabConfig.value = tabConfigData(res.layVoucherView.listTabConfig);
    setProps({
      api: customListData,
      beforeFetch: (params) => {
        params.url = listTabConfig.value.api;
        params.id_in = props.idIn;
        return params;
      },
      autoCreateKey: listTabConfig.value.autoCreateKey,
      bordered: listTabConfig.value.bordered,
      canResize: listTabConfig.value.canResize,
      clearSelectOnPageChange: listTabConfig.value.clearSelectOnPageChange,
      clickToRowSelect: listTabConfig.value.clickToRowSelect,
      // ellipsis: listTabConfig.value.ellipsis,
      // ellipsis: false,
      emptyDataIsShowTable: listTabConfig.value.emptyDataIsShowTable,
      inset: listTabConfig.value.inset,
      isTreeTable: listTabConfig.value.isTreeTable,
      // pagination: listTabConfig.value.pagination,
      showIndexColumn: listTabConfig.value.showIndexColumn,
      showSummary: listTabConfig.value.showSummary,
      showTableSetting: listTabConfig.value.showTableSetting,
      striped: listTabConfig.value.striped,
      useSearchForm: listTabConfig.value.useSearchForm,
      tableSetting: listTabConfig.value.tableSetting,
      titleHelpMessage: listTabConfig.value.titleHelpMessage,
      maxHeight: listTabConfig.value.maxHeight,
      resizeHeightOffset: listTabConfig.value.resizeHeightOffset,
    });
    if (!listTabConfig.value.immediate) {
      reload();
    }
  });

  // 表格嵌套的下拉选择
  const onClick: MenuProps['onClick'] = ({ key }) => {
    console.log(`Click on item ${key}`);
    if (key == 1) {
      showMessage;
    }
  };
  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerDrawer2, { openDrawer: openDrawer2 }] = useDrawer();
  const [registerBCDrawer, { openDrawer: openBCDrawer }] = useDrawer();
  const [registerTipDrawer, { openDrawer: openTipDrawer }] = useDrawer();
  const [registerPoolDrawer, { openDrawer: openPoolDrawer }] = useDrawer();
  const [registerRemarkDrawer, { openDrawer: openRemarkDrawer }] = useDrawer();
  const [registerSxDrawer, { openDrawer: openSxDrawer }] = useDrawer();
  const [registerTable, { reload, getForm, setProps }] = useTable({
    columns: tableColumns,
    formConfig: searchForm.value,
    ellipsis: false,
    pagination: {
      pageSize: 100,
    },
  });
  // 刷新表格数据（含表单回调）
  function handleSuccess() {
    reload();
  }

  function addDebugData(record: Recordable) {
    let obj = {
      id: record.id,
      taskCode: record.task.taskCode,
      machineId: record.code,
      operCode: record.task.oper.operCode,
      picno: record.task.orderPic.picno,
    };
    openDebugModal(true, obj);
  }
  function addCheckData(record, checkType) {
    let obj = {
      'task.taskCode': record.task.taskCode,
      machineId: record.code,
      checkType: checkType,
    };
    openCheckForm(true, obj);
  }

  function addOverData(record, type, ope) {
    let obj = {
      id: record.id,
      taskCode: record.task.taskCode,
      machineId: record.code,
      operCode: record.task.oper.operCode,
      overType: type,
      ope: ope,
      picno: record.task.orderPic.picno,
      picname: record.task.orderPic.picname,
      machineStatus: record.machineStatus,
    };
    openModal(true, obj);
  }
  function addHandData(record) {
    console.log(record);
  }

  //addHandData
  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  function handleSj(record: Recordable) {
    openTipDrawer(true, { openType: '0' });
  }

  function handleGcj(record: Recordable) {
    openTipDrawer(true, { openType: '1' });
  }

  async function add(record: Recordable) {
    openDrawer(true, record);
  }

  // 编程反馈
  const handleBC = (record) => {
    openBCDrawer(true, record);
  };

  function addRemark(record: Recordable) {
    if (record.task) {
      openRemarkDrawer(true, {
        taskCode: record.task.taskCode,
        operCode: record.task.oper.operCode,
        machineId: record.code,
      });
    } else {
      showMessage('当前机床无任务加工！');
    }
  }
  async function machineEnable(code, type) {
    let res = {
      message: '',
    };
    let data = {
      code,
      eventCode: type,
    };
    if (type == '0') {
      res = await disable(data);
    } else {
      res = await enable(data);
    }
    showMessage(res.message);
    handleSuccess();
  }
  // 首检提示
  async function handleBsj(record: Recordable) {
    if (record.task) {
      openCheckTipModal(true, { ...record });
    } else {
      showMessage('任务信息缺失，请刷新后重试！');
    }
  }

  async function remarksPush(record) {
    if (record.task) {
      picId.value = record.task.orderPic.id;
      openRemarkskDrawer(true);
    } else {
      showMessage('当前机床无备注！');
    }
  }

  async function openPool(record: Recordable) {
    openPoolDrawer(true, {
      title:
        '机床-' +
        record.name +
        '【' +
        (record.operNames ? record.operNames.replaceAll(',', '-') : '') +
        '】',
      machine: record.code,
      orderPic: record.task && record.task.orderPic,
      taskCode: record.task && record.task.taskCode,
      openType: '2',
    });
  }

  // 更新机床时间
  const handleRefresh = async () => {
    const res = await refresh();
    showMessage(res.message);
    reload();
  };

  function orderCheckList(record) {
    taskCode.value = record;
    openCheckDrawer(true);
  }

  function handleRouterList(record) {
    orderPic.value = record;
    openSxDrawer();
  }

  function openTaskList(record) {
    taskCode.value = record;
    openTaskDrawer();
  }

  //导出数据
  function btnExport() {
    var formdata = getForm().getFieldsValue();
    formdata = { ...formdata, ...props, idIn: props.idIn?.split(',') };
    console.log(formdata);
    handleExport('/m8/machine/exportData', formdata);
  }
</script>
<style lang="css" scope>
  .jeesite-editable-cell__action {
    display: none;
  }
  /* .ant-select-show-search {
    width: 100% !important ;
  } */
  .edit-cell-align-center {
    width: 100% !important;
  }
</style>
